﻿using Harmontronics.Model.Entitys;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Reflection;

namespace Harmontronics.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ToolController : ControllerBase
    {
        private readonly ISqlSugarClient _db;

        public ToolController(ISqlSugarClient db)
        {
            _db = db;
        }

        //[HttpGet]
        //public string InitDateBase()
        //{
        //    string res = "Db initialized";

        //    try
        //    {
        //        _db.DbMaintenance.CreateDatabase();
        //        Type[] ass = Assembly.LoadFrom(AppContext.BaseDirectory + "Harmontronics.Model.dll").GetTypes().Where(t => t.Namespace == "Harmontronics.Model.Entitys").ToArray();
        //        _db.CodeFirst.SetStringDefaultLength(200).InitTables(ass);

        //        //初始化数据
        //        Users user = new Users()
        //        {
        //            //Name = "admin",
        //            //NickName = "超级管理员",
        //            //Password = "123456",
        //            //UserType = 0,
        //            //IsEnable = true,
        //            //Description = "数据库初始化时默认添加的超级管理员",
        //            //CreateTime = DateTime.Now,
        //            //CreateUserId = 0,
        //            //IsDeleted = 0
        //        };
        //        long userId = _db.Insertable(user).ExecuteReturnBigIdentity();
        //        Menu menuRoot = new Menu()
        //        {
        //            //Name = "菜单管理",
        //            //Index = "menumanager",
        //            //FilePath = "../views/admin/menu/MenuManager",
        //            //ParentId = 0,
        //            //Order = 0,
        //            //IsEnable = true,
        //            //Description = "数据库初始化时默认添加的默认菜单",
        //            //CreateTime = DateTime.Now,
        //            //CreateUserId = userId,
        //            //IsDeleted = 0
        //        };
        //        _db.Insertable(menuRoot).ExecuteReturnBigIdentity();
        //    }
        //    catch (Exception ex)
        //    {
        //        res = "Db initialize failed. " + ex.Message;
        //    }

        //    return res;
        //}

        [HttpGet]
        public string Test()
        {
            return "OK";
        }
    }
}
